package com.forcast;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.forcast.forcast;
import com.VO.zhugeVO;

/**
 * Servlet implementation class forcast
 */
public class forcast extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public forcast() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("Start doPost");
		ZhuGeNum z = new ZhuGeNum();
		String num= request.getParameter("num");
		String word = request.getParameter("word");
		zhugeVO zv = z.getQbyWords(word);
		//request.setAttribute("zv", zv);
		String r="{\"Qno\":\""+zv.getQno()+"\",\"Qdetail\":\""+zv.getQdetail()+"\",\"Qexplain\":\""+zv.getQexplain()+"\"}";
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json");
		  PrintWriter out = response.getWriter();
		  out.print(r);
		  out.flush();
		  out.close();
		//request.getRequestDispatcher("main.jsp").forward(request, response);
		System.out.println("num: "+num);
		System.out.println("name: "+word);
	}

}
